﻿
<template>
    <el-row :gutter="20" style="height:60px;padding:20px;" type="flex">
        <el-col :span="5">
            <div class="input-group" style="margin-bottom:10PX;">
                <div class="input-group-btn">
                    <button type="button" style="height: 34px;min-width:80PX" class="btn btn-primary  dropdown-toggle">管理站</button>
                </div>
                <el-select placeholder="选择管理站" size="mini" v-model="tkjc" class="form-control filter" style="height: 34px;padding:0px;" @change="sellb" clearable filterable>
                    <el-option-group v-for="zz in bms"
                                     :key="zz.DeptCode"
                                     :label="zz.DeptName">
                        <el-option v-for="item in zz.ChildBranch"
                                   :key="item.DeptCode"
                                   :label="item.DeptName"
                                   :value="item.DeptCode">
                        </el-option>
                    </el-option-group>
                </el-select>
            </div>
        </el-col>
        <el-col :span="10">
            <div class="input-group" style="margin-bottom:10PX;">
                <div class="input-group-btn">
                    <button type="button" style="height: 34px;min-width:80PX" class="btn btn-primary  dropdown-toggle">用水时间</button>
                </div>


                <el-select placeholder="灌溉年度" size="mini" v-model="ggnd" class="form-control filter" style="height: 34px;padding:0px;width:40%">
                    <el-option-group v-for="group in ggnddata"
                                     :key="group.TypeNO"
                                     :label="group.TypeNO">
                        <el-option v-for="item in group.gjdata"
                                   :key="item.LB"
                                   :label="group.TypeNO+'-'+item.LB"
                                   :value="item.KSSJ+','+item.JSSJ">
                        </el-option>
                    </el-option-group>
                </el-select>
                <el-date-picker v-model="qzsj" size="mini" class="form-control filter" style="height: 34px;padding:0px;width:60%;line-height:34px"
                                type="daterange"
                                value-format="yyyy-MM-dd"
                                range-separator="至"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期">
                </el-date-picker>
            </div>

        </el-col>
        <el-col :span="10">
        </el-col>
    </el-row>
</template>


<script>
    //输出得查询格式必须为{ colid: obj.cxzd, cal: obj.cal, val: va.itemtext }，colid为字段,cal为查询类型(0:等于,1:包含-逗号隔开).val为值
    module.exports = {
        props: ['pzoption'],
        data() {
            return {
                isshow: false,
                tkjc: "",
                ggnddata: [],
                sdate: "",
                edate: "",
                ggnd: "",
                qzsj: "",
                bms: [],
            };
        },
        computed: {

        },
        methods: {
            getq: function () {
                var chi = this;

                chi.pzoption.value = [];
                if (chi.tkjc) {
                    chi.pzoption.value.push({ colid: "zid", cal: "0", val: chi.tkjc });
                }
                chi.pzoption.value.push({ colid: "crdate", cal: "5", val: chi.qzsj.join() });


            },
            sellb: function (val) {
                if (val) {
                    this.pzoption.value = [{ colid: "zid", cal: "0", val: val }];
                } else {
                    this.pzoption.value = [];
                }
                this.getq();
                this.$parent.Query();
            },
        },
        watch: {
            'qzsj': { //深度监听，可监听到对象、数组的变化
                handler(newV, oldV) {
                    var chi = this;
                    if (newV) {
                        this.getq();
                        this.$parent.Query();
                    }
                },
                deep: true
            },
            'ggnd': { //深度监听，可监听到对象、数组的变化
                handler(newV, oldV) {
                    var chi = this;
                    if (newV) {
                        chi.qzsj = [newV.split(",")[0], newV.split(",")[1]];
                    }
                },
                deep: true
            }

        },
        mounted: function () {
            var chi = this;
            chi.$nextTick(function () {
                $.getJSON('/api/Auth/ExeAction?Action=GETALLBMNEW', {}, function (resultData) {
                    chi.bms = resultData.Result[0].ChildBranch;
                })
                chi.ggnddata = JSON.parse(ComFunJS.getCookie("ggnd"));
                chi.sdate = chi.ggnddata[0].gjdata[0].KSSJ;
                chi.edate = chi.ggnddata[0].gjdata[2].JSSJ;

                var isnow = false;
                _.forEach(chi.ggnddata, function (obj) {
                    _.forEach(obj.gjdata, function (gj) {
                        if (gj.ISNOW == 'Y') {
                            isnow = true;
                            chi.sdate = gj.KSSJ;
                            chi.edate = gj.JSSJ;
                            chi.ggnd = gj.KSSJ + "," + gj.JSSJ;
                        }
                    })
                })
                if (!isnow) {
                    chi.ggnd = chi.sdate + "," + chi.edate;

                }
                chi.qzsj = [chi.sdate, chi.edate];
            })

        }
    };
</script>